<?php

namespace App\Transformers;

use League\Fractal\TransformerAbstract;
use App\Models\Dorm;

/**
 * Class DormTransformer.
 *
 * @package namespace App\Transformers;
 */
class DormTransformer extends TransformerAbstract
{
    /**
     * Transform the Dorm entity.
     *
     * @param \App\Models\Dorm $model
     *
     * @return array
     */
    public function transform(Dorm $model)
    {
        return [
            'id'         => (int) $model->id,
            'company'       => $model->company,
            'building_name' => optional($model->building)->name,
            'building_id' => $model->building_id,
            'dorm_type_name' => optional($model->dormType)->name,
            'dorm_type_id' => $model->dorm_type_id,
            'for_gender' => $model->for_gender ? ($model->for_gender == 1 ? '男' : '女') : '',
            'code' => $model->code,
            'record_order' => $model->record_order,
            'floor' => $model->floor,
            'unit_name' => $model->unit_name,
            'beds' => $model->beds,
            'beds_take' => $model->staffs_count,
            'water_meter_id' => optional($model->activeWaterMeter)->id,
            'hot_water_meter_id' => optional($model->activeHotWaterMeter)->id,
            'electric_meter_id' => optional($model->activeElectricMeter)->id,
            'created_at' => $model->created_at->format('Y-m-d H:i:s'),
            'updated_at' => $model->updated_at->format('Y-m-d H:i:s'),
        ];
    }
}
